﻿using Microsoft.Extensions.DependencyInjection;



namespace BlogDemo.Api.Extensions
{

    public static class SwaggerConfig
    {
        /// <summary>
        /// Add Swagger middleware
        /// </summary>
        public static IServiceCollection AddSwagger(this IServiceCollection services)
        {
            // Register the Swagger generator, defining 1 or more Swagger documents
            //services.AddSwaggerGen(c =>
            // {
            //     c.SwaggerDoc(Constants.Swagger.Version, new OpenApiInfo { Title = "BlogDemo.Api", Version = "v1" });

            //     // Set the comments path for the Swagger JSON and UI.
            //     var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            //     var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
            //     if (File.Exists(xmlPath))
            //     {
            //         c.IncludeXmlComments(xmlPath);
            //     }
            // });

            //DI handler process function
            //services.AddSingleton<IAuthorizationHandler, PolicyHandler>();
            //services.AddSwaggerGen(c =>
            //{
            //    c.SwaggerDoc("v1", new OpenApiInfo { Title = "BlogDemo WebAPI", Version = "v1",Description = "接口说明文档", Contact = new OpenApiContact { Name = "397593286", Email = "397593286@qq.com" } });
            //    var securityScheme = new OpenApiSecurityScheme
            //    {
            //        Name = "JWT Authentication",
            //        Description = "Enter JWT Bearer token **_only_**\nJWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}（注意两者之间是一个空格）\"",
            //        In = ParameterLocation.Header,//jwt默认存放Authorization信息的位置(请求头中)
            //        Type = SecuritySchemeType.Http,
            //        Scheme = "bearer",
            //        BearerFormat = "JWT",
            //        Reference = new OpenApiReference
            //        {
            //            Id = JwtBearerDefaults.AuthenticationScheme,
            //            Type = ReferenceType.SecurityScheme
            //        }
            //    };
            //    //    // 开启小锁
            //    //    c.OperationFilter<AddResponseHeadersFilter>();
            //    //    c.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
            //    //    // 在header中添加token，传递到后台
            //    //    c.OperationFilter<SecurityRequirementsOperationFilter>();

            //    c.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme);
            //    c.AddSecurityRequirement(new OpenApiSecurityRequirement { { securityScheme, new string[] { } } });


            //    //    var basePath = AppContext.BaseDirectory;
            //    //    var xmlPath = Path.Combine(basePath, "BlogDemo.Api.xml");
            //    //    c.IncludeXmlComments(xmlPath, true); //接口注释信息
            //    //   //c.IncludeXmlComments(Path.Combine(basePath, "BlogDemo.Core.xml"), true); //Model注释信息
            //});


            return services;
        }
    }
}
